package com.cloud.controller;

import com.cloud.service.GarageService;
import com.cloud.dto.GarageDto;
import com.cloud.model.Garage;
import com.cloud.dto.RequestDto;
import com.cloud.dto.ResponseDto;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

/**
 * Created by util on 2018-4-27.
 */
@Api(description = "garage相关api")
@RestController
@RequestMapping("/garage")
public class GarageController {

    @Autowired
    private GarageService garageService;

    @PostMapping("/selectGarageList")
    @ApiOperation(value = "获取garage列表")
    public ResponseDto<List<Garage>> selectGarageList(@RequestBody RequestDto<GarageDto> requestDto){
        List<Garage> garageList = garageService.selectGarageList(requestDto.getModel());
        return ResponseDto.successWithData(garageList);
    }
    
    @PostMapping("/selectGaragePage")
    @ApiOperation(value = "获取garage分页列表")
    public ResponseDto<PageInfo<Garage>> selectGaragePage(@RequestBody RequestDto<GarageDto> requestDto){
        PageInfo pageInfo = garageService.selectGaragePage(requestDto.getModel());
        return ResponseDto.successWithData(pageInfo);
    }

    @PostMapping("/selectGarageById")
    @ApiOperation(value = "通过id获取garage")
    public ResponseDto<Garage> selectGarageById(@RequestBody RequestDto<GarageDto> requestDto){
        Garage garage = garageService.selectGarageById(requestDto.getModel());
        return ResponseDto.successWithData(garage);
    }

    @PostMapping("/insertGarage")
    @ApiOperation(value = "通过garage新增")
    public ResponseDto<Boolean> insertGarage(@RequestBody RequestDto<GarageDto> requestDto){
        boolean flag = garageService.insertGarage(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }

    @PostMapping("/updateGarage")
    @ApiOperation(value = "通过garage更新")
    public ResponseDto<Boolean> updateGarage(@RequestBody RequestDto<GarageDto> requestDto){
        boolean flag = garageService.updateGarage(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }

    @PostMapping("/deleteGarage")
    @ApiOperation(value = "通过garage删除")
    public ResponseDto<Boolean> deleteGarage(@RequestBody RequestDto<GarageDto> requestDto){
        boolean flag = garageService.deleteGarage(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }
    
}
